package com.software.chemistry.repository;

import com.software.chemistry.entity.SearchHistory;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface SearchHistoryRepository extends JpaRepository<SearchHistory, String> {


    List<SearchHistory> findByUserIdOrderByHistoryTimeDesc(String userId);

    List<SearchHistory> findByUserId(String userId);

    @Transactional
    @Modifying
    @Query(value ="delete from search_history where user_id = ?1", nativeQuery = true)
    void deleteByUserId(String userId);
}
